/*********************TCP发送函数*********************/
#include "connect.h"
void tcpclient(void)
{
    int tsockfd;    //连接后的套接字
    struct sockaddr_in servaddr;
    char ttransbuf[128];//tcp传输用的buf
    //scanf("%s",&ttransbuf);
    //建立socket连接
    if (-1 == (tsockfd = socket(AF_INET,SOCK_STREAM,0)))
    {
        perror("socket");
        exit(-1);
    }
    //printf("tlistenfd is %di\n",tlistenfd);
    //设置sockaddr_in结构体中相关的参数
    bzero(&servaddr,sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(atoi("9999"));
    servaddr.sin_addr.s_addr = inet_addr("0.0.0.0");
    //调用connect向服务器请求
    if (-1 == connect(tsockfd,(struct sockaddr *)&servaddr,sizeof(servaddr)))
    {
        perror("connect");
        //endwin();
        //erase();
        //refresh();
        exit(-1);
    }
    while (1)
    {
    printf("please input:\n");
    gets(ttransbuf);

    //strcpy(ttransbuf,sentmsg);
    send(tsockfd,ttransbuf,sizeof(ttransbuf),0);
    printf("message %s sented\n",ttransbuf);
    }
    close(tsockfd);
    exit(0);
}
